package com.s59.mapper;


import com.s59.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class UserMapperimpl implements UserMapper {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public int add(User user){
        return jdbcTemplate.update("insert into user(name,account,bmid) values (?,?,?)",user.getName(),user.getAccount(),user.getBmid());

    }

    public int del(Long id){
        return jdbcTemplate.update("delete from user where id = ?",id);
    }


    public int update(User user){
        return jdbcTemplate.update("update user set name = ?,account = ?,bmid = ? where id = ?",user.getName(),user.getAccount(),user.getBmid(),user.getId());
    }

    public User get(Long id) {
        return jdbcTemplate.queryForObject("select * from user where id = ?", BeanPropertyRowMapper.newInstance(User.class),id);
    }

    public List<User> getall(){
        return jdbcTemplate.query("select * from user ",BeanPropertyRowMapper.newInstance(User.class));

    }
}
